/*
 * Licensed under the MIT License
 * 
 * Copyright (c) 2011 Kay Kreuning
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 * http://code.google.com/p/hyves-as3-sdk/
 */
package nl.hyves.api.methods
{
	import nl.hyves.api.utils.JSONMapper;
	import nl.hyves.api.valueobjects.ImageVO;
	import nl.hyves.api.valueobjects.MediaVO;

	import com.adobe.cairngorm.contract.Contract;

	public class Media
	{
		public static const GET:String = 'media.get';
		public static const GET_BY_ALBUM:String = 'media.getByAlbum';
		public static const GET_UPLOAD_TOKEN:String = 'media.getUploadToken';
		public static const UPDATE:String = 'media.update';
		{
		JSONMapper.registerMapping('media', MediaVO);
		JSONMapper.registerMapping('icon_small', ImageVO);
		JSONMapper.registerMapping('icon_medium', ImageVO);
		JSONMapper.registerMapping('icon_large', ImageVO);
		JSONMapper.registerMapping('icon_extralarge', ImageVO);
		JSONMapper.registerMapping('image', ImageVO);
		JSONMapper.registerMapping('image_fullscreen', ImageVO);
		JSONMapper.registerMapping('square_large', ImageVO);
		JSONMapper.registerMapping('square_extralarge', ImageVO);
		}
		public static function get(mediaid:String):IMethod
		{
			Contract.precondition(mediaid && mediaid != '');

			return new Method(GET, {mediaid: mediaid});
		}

		public static function getByAlbum(albumid:String):IMethod
		{
			Contract.precondition(albumid && albumid != '');

			return new Method(GET_BY_ALBUM, {albumid: albumid});
		}

		public static function getUploadToken():IMethod
		{
			return new Method(GET_UPLOAD_TOKEN);
		}

		public static function update(mediaid:String, title:String = '', description:String = ''):IMethod
		{
			Contract.precondition(mediaid && mediaid != '');

			var parameters:Object = {mediaid: mediaid};

			if (title) parameters['title'] = title;
			if (description) parameters['description'] = description;

			Contract.postcondition(parameters != null);

			return new Method(UPDATE, parameters);
		}
	}
}
